public class LC01 {
     public class ListNode {
         int val;
         ListNode next;
         ListNode() {}
         ListNode(int val) { this.val = val; }
         ListNode(int val, ListNode next) { this.val = val; this.next = next; }
     }

    class Solution {
        public ListNode removeElements(ListNode head, int val) {
            //终止条件
            if (head == null) {
                return head;
            }
            //自身调用
            head.next = removeElements(head.next, val);
            //如果head的节点值为val，那么新的头节点为head.next，否则为head
            return head.val == val ? head.next : head;
        }
    }

}
